
package net.atremmedia.gwt.actionjava.examples.sgi;

import actionjava.anim.Anim;
import actionjava.anim.config.Manifest;
import actionjava.anim.ease.ExpoInOut;
import actionjava.anim.ease.ExpoOut;
import actionjava.display.Bitmap;
import actionjava.display.BitmapData;
import actionjava.display.Graphics;
import actionjava.display.Shape;
import actionjava.geom.Color;

public class ImgGalleryItem extends Bitmap
{
	private Shape itemMask;
	private ImgGalleryItemVO item;

	public ImgGalleryItem(ImgGalleryItemVO item)
	{
		super(new BitmapData(item.getImgUrl()));
		this.item = item;
		initialize();
	}

	private void initialize()
	{
		createMask();
		setAlpha(0);
		setX(-270);
		setY(-100);
		setMask(itemMask);
	}

	private void createMask()
	{
		itemMask = new Shape();
		Graphics graph = itemMask.getGraphics();
		graph.beginStroke("#000");
		graph.beginFill(Color.getRGBA(0xFF0000, 1));
		try {
			graph.decodePath("AmWPnQr7hJnpnMIwR25MBUXAAAIAAfOg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		graph.closePath();
	}

	public void animateIn()
	{
		setAlpha(0);
		setX(100);

		Anim.tween(new Manifest(this, 1.5, ExpoOut.ease)
		{
			@Override
			protected void configure()
			{
				to(X, -270);
			}
		});

		Anim.tween(new Manifest(this, 1, ExpoInOut.ease)
		{
			@Override
			protected void configure()
			{
				to(ALPHA, 1);
			}
		});
	}

	public void animateOut()
	{
		setAlpha(1);

		Anim.tween(new Manifest(this, 1, ExpoInOut.ease)
		{
			@Override
			protected void configure()
			{
				to(ALPHA, 0);
			}
		});
	}

	public String getColor()
	{
		return item.getColor();
	}

	public String getText()
	{
		return item.getText();
	}

	public double getTextX()
	{
		return item.getX();
	}

	public double getTextY()
	{
		return item.getY();
	}
}
